// ./store
import Vue from 'vue'
import Vuex from 'vuex'
import iUser from '../api/user'

Vue.use(Vuex)

export default new Vuex.Store({
  modules: {},

  state: {
    userInfo: {
      _id: '',
      name: '',
      role: null
    },
    routes: []
  },

  mutations: {
    setUserInfo (state, payload) {
      state.userInfo = payload
    }
  },

  actions: {
    async initUserInfo ({ commit }) {
      const userInfo = await iUser.getCurrentUser()
      commit('setUserInfo', userInfo)
    }
  }

})
